feat: implement DX Phase 2 define* helpers and enhance ObjectSchema.create()#643
feat: implement DX Phase 2 define* helpers and enhance ObjectSchema.create()#643
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…reate() - Add defineView(), defineApp(), defineFlow(), defineAgent() factory functions - Enhance ObjectSchema.create() with auto-label from snake_case and validation - Export all new helpers from root index.ts - Add comprehensive tests (21 new tests, 5178 total) - Update DX_ROADMAP.md Phase 2 checklist Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Implements DX Roadmap Phase 2 helper factories across @objectstack/spec, making definition creation consistent (validated + defaults applied) and improving ObjectSchema.create() ergonomics.
Changes:
- Enhanced
ObjectSchema.create()to auto-generatelabelfromnameand validate/apply defaults via Zod.parse(). - Added
defineView(),defineApp(),defineFlow(),defineAgent()helper factories plus corresponding tests. - Re-exported new DX helpers from the root
src/index.tsand updated DX roadmap checklist.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/spec/src/ui/view.zod.ts | Adds defineView() factory that parses ViewSchema input. |
| packages/spec/src/ui/view.test.ts | Adds tests for defineView() behavior and validation failures. |
| packages/spec/src/ui/app.zod.ts | Adds defineApp() factory that parses AppSchema input. |
| packages/spec/src/ui/app.test.ts | Adds tests for defineApp() defaults and validation failures. |
| packages/spec/src/index.ts | Re-exports defineView/defineApp/defineFlow/defineAgent from root. |
| packages/spec/src/data/object.zod.ts | Enhances ObjectSchema.create() with auto-label + .parse() validation. |
| packages/spec/src/data/object.test.ts | Adds tests covering ObjectSchema.create() label/defaults/validation. |
| packages/spec/src/automation/flow.zod.ts | Adds defineFlow() factory that parses FlowSchema input. |
| packages/spec/src/automation/flow.test.ts | Adds tests for defineFlow() defaults and validation failures. |
| packages/spec/src/ai/agent.zod.ts | Adds defineAgent() factory that parses AgentSchema input. |
| packages/spec/src/ai/agent.test.ts | Adds tests for defineAgent() defaults, tools, and validation failures. |
| DX_ROADMAP.md | Marks Phase 2 checklist items as completed. |
| return name | ||
| .split('_') |
There was a problem hiding this comment.
snakeCaseToLabel() can produce leading/trailing or double spaces when name contains leading underscores or consecutive underscores (allowed by the current /^[a-z_][a-z0-9_]*$/ regex). Consider normalizing by splitting on /_+/, filtering empty segments, and trimming the result before joining.
| return name | |
| .split('_') | |
| const segments = name | |
| .split(/_+/) | |
| .map(segment => segment.trim()) | |
| .filter(segment => segment.length > 0); | |
| if (segments.length === 0) { | |
| return ''; | |
| } | |
| return segments |
| export function defineApp(config: z.input<typeof AppSchema>): App { | ||
| return AppSchema.parse(config); | ||
| } |
There was a problem hiding this comment.
defineApp() duplicates the existing App.create() helper above. To avoid two factory entry points drifting over time, consider exporting defineApp as an alias of App.create (or removing one of them) so there’s a single source of truth for app parsing/defaults.
| export function defineApp(config: z.input<typeof AppSchema>): App { | |
| return AppSchema.parse(config); | |
| } | |
| export const defineApp = App.create; |
| export function defineFlow(config: z.input<typeof FlowSchema>): FlowParsed { | ||
| return FlowSchema.parse(config); | ||
| } | ||
|
|
||
| export type Flow = z.input<typeof FlowSchema>; | ||
| export type FlowParsed = z.infer<typeof FlowSchema>; |
There was a problem hiding this comment.
The return type FlowParsed is inconsistent with most other schemas, where the primary exported type name is the parsed (z.infer) shape and the input type is suffixed with Input. Consider renaming to export type Flow = z.infer<typeof FlowSchema> and export type FlowInput = z.input<typeof FlowSchema>, then have defineFlow() return Flow, to keep the public API consistent.
| export function defineFlow(config: z.input<typeof FlowSchema>): FlowParsed { | |
| return FlowSchema.parse(config); | |
| } | |
| export type Flow = z.input<typeof FlowSchema>; | |
| export type FlowParsed = z.infer<typeof FlowSchema>; | |
| export function defineFlow(config: FlowInput): Flow { | |
| return FlowSchema.parse(config); | |
| } | |
| export type Flow = z.infer<typeof FlowSchema>; | |
| export type FlowInput = z.input<typeof FlowSchema>; | |
| export type FlowParsed = Flow; |
Implements DX Roadmap Phase 2 schema helper functions, bringing
define*count from 1 to 6.ObjectSchema.create()enhancementNo longer a pass-through identity function. Now auto-generates
labelfrom snake_casenameand validates via.parse():New
define*()factoriesAll follow the
defineStudioPlugin()pattern — acceptz.input<Schema>, return parsed output with defaults applied and validation enforced:defineView()—src/ui/view.zod.tsdefineApp()—src/ui/app.zod.tsdefineFlow()—src/automation/flow.zod.tsdefineAgent()—src/ai/agent.zod.tsAll re-exported from root
src/index.tsfor top-level access:Tests
21 new tests across 5 files. Full suite: 191 files, 5178 tests passing.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.